package com.ktjy.ruoyidata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ktjy.ruoyidata.domain.MyItemType;
import com.ktjy.ruoyidata.service.IMyItemTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 物料产品分类Controller
 *
 * @author t382
 * @date 2025-04-29
 */
@RestController
@RequestMapping("/ruoyidata/type")
public class MyItemTypeController extends BaseController {
    @Autowired
    private IMyItemTypeService myItemTypeService;

    /**
     * 查询物料产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:list')")
    @GetMapping("/list")
    public AjaxResult list(MyItemType myItemType) {
        List<MyItemType> list = myItemTypeService.selectMyItemTypeList(myItemType);
        return success(list);
    }

    /**
     * 导出物料产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:export')")
    @Log(title = "物料产品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyItemType myItemType) {
        List<MyItemType> list = myItemTypeService.selectMyItemTypeList(myItemType);
        ExcelUtil<MyItemType> util = new ExcelUtil<MyItemType>(MyItemType.class);
        util.exportExcel(response, list, "物料产品分类数据");
    }

    /**
     * 获取物料产品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:query')")
    @GetMapping(value = "/{itemTypeId}")
    public AjaxResult getInfo(@PathVariable("itemTypeId") Long itemTypeId) {
        return success(myItemTypeService.selectMyItemTypeByItemTypeId(itemTypeId));
    }

    /**
     * 新增物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:add')")
    @Log(title = "物料产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyItemType myItemType) {
        myItemTypeService.insertMyItemType(myItemType);
        return success(myItemType); // 返回包含自动生成字段的完整对象
    }

    /**
     * 修改物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:edit')")
    @Log(title = "物料产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyItemType myItemType) {
        return toAjax(myItemTypeService.updateMyItemType(myItemType));
    }

    /**
     * 删除物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:type:remove')")
    @Log(title = "物料产品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{itemTypeIds}")
    public AjaxResult remove(@PathVariable Long[] itemTypeIds) {
        return toAjax(myItemTypeService.deleteMyItemTypeByItemTypeIds(itemTypeIds));
    }
}
